<route lang="json5" type="page">
{
  page: true,
  style: { navigationBarTitleText: '登录' },
}
</route>

<template>
  <view class="center pt-4 flex-col list-container">
    <view class="mb-3">
      <wd-button @click="login('AppIndexView')">登录并跳转首页</wd-button>
    </view>
    <view class="mb-3">
      <wd-button @click="login('MobViewTestMobMDView_confirm')">登录并跳转多数据视图</wd-button>
    </view>
  </view>
</template>

<script lang="ts" setup>
import { currRoute } from "@/utils";
import { useUserStore } from "@/store";
import { AuthGuard } from "@/guard";

const userStore = useUserStore();

const login = async (viewId: string) => {
  const res = await ibiz.net.post("/v7/login", {
    loginname: "preview_admin",
    password: "123456"
  });
  if (res.ok) {
    userStore.setUserInfo({
      nickname: "preview_admin",
      avatar: "",
      token: res.data.token
    });
    const authority = await AuthGuard();
    if (authority) {
      const { query } = currRoute();
      if (query.redirect) {
        uni.redirectTo({ url: query.redirect });
      } else {
        uni.redirectTo({ url: `/pages/demo/page/${viewId}` });
      }
    }
  }
};
</script>

<style lang="scss" scoped>
//
</style>
